/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.service.core.impl;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.persistence.core.BackupDAO;
import com.blandware.atleap.persistence.exception.BackupFileAccessException;
import com.blandware.atleap.service.core.BackupManager;

import java.util.Date;
import java.io.InputStream;

/**
 * <p>Manager for performing backup/restore database operations</p>
 * <p/>
 * <p><a href="BackupManagerImpl.java.html"><i>View Source</i></a></p>
 *
 * @author Andrey Grebnev <a href="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
 * @version $Revision: 1.5 $ $Date: 2007/06/06 13:43:01 $
 */
public class BackupManagerImpl extends BaseManagerImpl implements BackupManager  {

    /**
     * DAO to use with backup
     */
    protected BackupDAO backupDAO;

    /**
     * Set backup DAO
     * @param backupDAO
     */
    public void setBackupDAO(BackupDAO backupDAO) {
        this.backupDAO = backupDAO;
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#backup()
     */
    public void backup() throws BackupFileAccessException {
        backupDAO.backup();
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#restore(java.util.Date, Boolean)
     */
    public void restore(Date date, Boolean force) throws BackupFileAccessException {
        backupDAO.restore(date, force);
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#restore()
     */
    public void restore() throws BackupFileAccessException {
       restore((Date) null, Boolean.TRUE);
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#restore(java.io.InputStream, Boolean)
     */
    public void restore(InputStream inputStream, Boolean force) {
        backupDAO.restore(inputStream, force);
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#canListArchives()
     */
    public boolean canListArchives() {
        return backupDAO.canListArchives();
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#listArchives(com.blandware.atleap.common.util.QueryInfo)  
     */
    public PartialCollection listArchives(QueryInfo queryInfo) throws BackupFileAccessException {
        return backupDAO.listArchives(queryInfo);
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#createDirIfNotExists()
     */
    public boolean createDirIfNotExists() {
        return backupDAO.createDirIfNotExists();
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#getBackupFileData(java.util.Date)
     */
    public byte[] getBackupFileData(Date date) {
        return backupDAO.getBackupFileData(date);
    }

    /**
     * @see com.blandware.atleap.service.core.BackupManager#getBackupFileName(java.util.Date) 
     */
    public String getBackupFileName(Date date) {
        return backupDAO.getBackupFileName(date);
    }
}
